package org.estela.stats;

import java.io.Serializable;
import java.util.Arrays;

/**
 * 
 * @version 1.00
 * @date Apr 22, 2006
 * @author <a href="mailto:akantek@nyse.com">Antonio Kantek</a>
 */
public class Frequencies implements Serializable {
	private static final long serialVersionUID = 1L;

	/** */
	private double[] frequencies;
	
	/**
	 * 
	 * @param numFrequencies
	 */
	public Frequencies(int numFrequencies) {
		this.frequencies = new double[numFrequencies];
	}
	
	/**
	 * 
	 * @param frequency
	 */
	public void addFrequency(int freqIdx) {
		this.frequencies[freqIdx]++;
	}
	
	/**
	 * 
	 */
	public void reset() {
		Arrays.fill(this.frequencies, 0);
	}
	
	/**
	 * 
	 * @return
	 */
	public int getModalIndex() {
		int idx = 0;
		for(int i=1;i<this.frequencies.length;i++) {
			if (this.frequencies[idx] < this.frequencies[i]) {
				idx = i;
			}
		}
		return idx;
	}
	
	@Override
	public String toString() {
		StringBuilder buff = new StringBuilder();
		buff.append("[Frequencies frequencies=");
		buff.append(Arrays.toString(this.frequencies));
		buff.append(']');
		return buff.toString();
	}
	
	/**
	 * @return Returns the frequencies.
	 */
	public double[] getFrequencies() {
		return this.frequencies;
	}
}